/*
 * 文 件 名 : FmListAdapter.java
 * 版    权 : China Machi.Co.,Ltd.Copyright 2009-2011.All rights reserved
 * 描    述 : <描述>
 * 修 改 人 : lixg
 * 修改时间 : 2012-12-28
 * 跟踪单号 : <跟踪单号>
 * 修改单号 : <修改单号>
 * 修改内容 : <修改内容>
 */
package com.fire8.dolphin.ui.wiget;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fire8.dolphin.common.Constants;
import com.fire8.dolphin.model.FmEntity;
import com.fire8.dolphin.model.Friend;
import com.fire8.dolphin.ui.R;
import com.fire8.dolphin.ui.imgcache.AsynLoad;
import com.fire8.dolphin.utils.LogUtil;
import com.fire8.dolphin.utils.StringUtil;
import com.fire8.dolphin.web.RequestUtils;

/**
 * 播放列表适配器
 * <功能详细描述>
 *
 * @author  lixg
 * @version [版本号,2012-12-28]
 * @see     [相关类/方法]
 * @since   [产品/模块]
 */
public class FmListAdapter  extends BaseAdapter
{
    private Activity context;
    private LayoutInflater mInflater;
    private Map<Integer,View> viewMap;
    private List<FmEntity> list;
    private AsynLoad asynLoad;
    public FmListAdapter(Activity ct,List<FmEntity> fms)
    {
        this.context = ct;
        this.mInflater = LayoutInflater.from(ct);
        viewMap = new HashMap<Integer, View>();
        this.list = fms;
        asynLoad = new AsynLoad();
    }
    
    public int getCount()
    {
        return list.size();
    }
    
    public Object getItem(int position)
    {
        return null;
    }
    
    public long getItemId(int position)
    {
        return 0;
    }
    
    public View getView(int position, View convertView, ViewGroup parent)
    {
        
        View rowView = viewMap.get(position);
        ViewHolder holder = null; 
        if (rowView == null)
        {
            holder = new ViewHolder();
            rowView = mInflater.inflate(R.layout.fm_list_item, null);
            holder.img = (ImageView)rowView.findViewById(R.id.img_fm);
            holder.tvTitle = (TextView)rowView.findViewById(R.id.tv_title);
            holder.tvPlay = (TextView)rowView.findViewById(R.id.tv_player);
            holder.tvDesc = (TextView)rowView.findViewById(R.id.tv_desc);
            rowView.setTag(holder);
            viewMap.put(position, rowView);
        }
        else
        {
            holder = (ViewHolder)rowView.getTag();
        }
        FmEntity fm = list.get(position);
        
        holder.tvTitle.setText(fm.getTitle());
        holder.tvPlay.setText(fm.getPlayer());
        holder.tvDesc.setText(fm.getDesc());
        if(!StringUtil.isEmpty(fm.getImg()))
        {
            //LogUtil.d("img:"+fm.getImg());
            asynLoad.showimgAnsy(holder.img,RequestUtils.IMG_URL+fm.getImg());
        }
        
        return rowView;
    }
    class ViewHolder
    {
        public ImageView img;
        public TextView tvTitle;
        public TextView tvPlay;
        public TextView tvDesc;
        
    }
}
